package org.project.curriculum.api;

import io.swagger.annotations.ApiOperation;
import org.project.curriculum.api.Params.userParam;
import org.project.curriculum.exception.LoginException;
import org.project.curriculum.exception.ParamException;
import org.project.curriculum.service.impl.employeeServiceImpl;
import org.project.curriculum.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Auther: hzy
 * @Date: 2022/2/20 13:10
 * @Description:
 */
@RestController
@RequestMapping(value = "/api/employAccount")
public class employAccountAPI {

    @Autowired
    private employeeServiceImpl employeeService;

    @PostMapping(value = "/login")
    @ApiOperation(value = "登录接口")
    Result<String> Login(@RequestBody userParam userParam, HttpSession session) throws LoginException, ParamException {

        if (userParam.getAccount().isEmpty()||userParam.getPassword().isEmpty())
            throw new ParamException("参数缺失");
        boolean result = employeeService.LoginByEmployee(userParam.getAccount(),
                userParam.getPassword());
        if (result){
            session.setAttribute("loginUser",userParam);
            return new Result<>(200, "SUCCESS","登录成功");
        }
        else
            return new Result<>(403, "FAIL","登录失败");
    }
}
